//
//  JRMainTabBarController.swift
//  myWeibo
//
//  Created by 樊健荣 on 16/7/18.
//  Copyright © 2016年 樊健荣. All rights reserved.
//

import UIKit

class JRMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //加载tabBar的控制器
        loadViewControllers()
        
        //加载自定义tabBar
        loadCustomTabBar()
        
    }
    //加载自定义tabBar
    private func loadCustomTabBar () -> Void {
        let tabbar = JRrootTabBar()
        tabbar.composeCallBack = {
            print("JRMainTabBarController准备跳转")
        }
        self.setValue(tabbar, forKey: "tabBar")
        
    }
    
    ///加载VCs
    private func loadViewControllers () -> Void {
        //首页
        let homeVC = JRHomeTableViewController()
        loadViewController(homeVC, title: "首页", imageName: "tabbar_home")
        //信息
        let messageVC = JRMessageTableViewController()
        loadViewController(messageVC, title: "信息", imageName: "tabbar_message_center")
        //发现
        let discoveryVC = JRDiscoveryTableViewController()
        loadViewController(discoveryVC, title: "发现", imageName: "tabbar_discover")
        //我
        let profileVC = JRProfileTableViewController()
        loadViewController(profileVC, title: "我", imageName: "tabbar_profile")
        
        
        
        
        
    }
    ///加载VC
    private func loadViewController (controller: UIViewController, title: String, imageName: String)-> Void {
        
        
        
        self.addChildViewController(UINavigationController(rootViewController: controller))
//        controller.tabBarItem.title = title
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        //拼接selectedName
        let selectedName = imageName + "_selected"
        //设置选择图片为不渲染,使用默认图片,不使用tineColor的原因是它只会使用在normal状态下的图片进行渲染颜色
        controller.tabBarItem.selectedImage = UIImage(named: selectedName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
    }
    
    

}
